<?
/**
 * Engine One PDF creator
 *
 * @copyright oneDot only <we@onedotonly.be>
 * @author Koen Betsens <koen@onedotonly.be>
 * @package Engine
 * @license GNU Lesser General Public License
 */

require_once( "engine/www/combustion.php" );


// Check if required paramaters are present
if( !( $id = (int) $_GET[ 'id' ]) || !( $type = $DB->simplestring( $_GET[ 'type' ]))) exit( 'Request error.' );




//$path = ENGINE_CORE . "../ext/dompdf/dompdf.php?paper=A4&input_file=". rawurlencode( "http://short-ski.com/foo.txt" ) ."";


//header("Content-type: application/pdf");

require_once( ENGINE_CORE . "../ext/dompdf/dompdf_config.inc.php" );


$dompdf = new DOMPDF();
$dompdf->load_html_file( "http://short-ski.com/o/pdf/.../$id?objtype=$type" );
$dompdf->render();
$dompdf->stream( ACCOUNT . " $type.$id.pdf" );






/*



// check if file already exists in db
if( $id = (int) $DB->get_key( "pdf", "meta like '%hook%atom%'", "ID" )) {

	$file = new OBJECT( "rss", $id );

} else {

	$file	= new OBJECT( "rss", 0, true );
	$textid	= $Engine->text->set( "atom", 0, "short", engine_get( 'lang.master' ));
	
	$file->set( "meta", json_encode( array( "hook" => "atom" )));
	$file->set( "nameid", $textid );

	$stick = true;
	
}

// create or get file name
$file_name = ROOT . ACCOUNT . "/www/DB/files/atom.{$file->id}.rss";

// check for updates
if( $stick || $DB->get_key( "news", "flog > '{$file->get( 'llog' )}'", "ID" )) {

	$fw = @fopen( $file_name, 'w') or die("can't open file");
	
	// check for future atom (for the prevous 24)
	$now = date('Y-m-d', time());
	if ( $nodes = $DB->filter( "news", "active && date < now() order by date desc LIMIT 24" )) {
	
	$page	= new PAGE( json_decode( $DB->type( "news", "meta" ))->pageid );
	$url	= $page->url();
		
		// header for the xml
		$feed = "<?xml version='1.0' encoding='UTF-8' ?>\n";
		$feed .= "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n";
		$feed .= "<title>". engine_get('title.control') . "</title>\n";
		$feed .= "<link href=\"" . engine_get('url') . "\" />\n";
		$feed .= "<updated>". $file->get( "flog", date( "Y-m-d H:i:s" )) ."</updated>\n";
	
		// walk rows
		foreach ( $nodes as $node ) {
			
			$name = htmlspecialchars(str_replace('&', '&amp;', $node['name']));
			
			$feed .= "\t<entry>\n";
			$feed .= "\t\t<title>" . $name . "</title>\n";
			$feed .= "\t\t<link href='" . $url . "?news_id=" . $node['ID'] . "' />\n";
			$feed .= "\t\t<updated>" . date('Y-m-d H:i:s', strtotime($node['date'])) . "</updated>\n";
			$feed .= "\t\t<id>tag:" . engine_get('title.control') . "," . date('Y-m-d', strtotime($node['flog'])) . ":" . $node['ID'] . "</id>\n";
			$feed .= "\t</entry>\n\n";
		
		}
		
		// end the xml
		$feed .= "</feed>";

	}
		
	$file->set( "llog", date( "Y-m-d H:i:s" ));
		
	fwrite( $fw, $feed );
	fclose( $fw );

// read old file if there weren't any updates
} else {

	$fh = fopen( $file_name, 'r' ) or die( "can't open file" );
	$feed = fread( $fh, filesize( $file_name ));

}

// print xml
header("Content-type: text/xml");
print $feed;
*/

?>